#include "dsp.h"

DisplayStruct dsp;

/*数码管段码表*/ //0~9,A~F,'-',小数点,'U',全灭,H,P,L，N(这里的N其实显示的是小写的‘n’)                                                                        
code unsigned char segCode[24]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,0xbf,0x7f,0xc1,0xff,0x89,0x8c,0xc7,0xc8}; 

//
DisplayStruct* GetDisplayStruct(void)
{
    return &dsp;
}

//
void SegDisplay(void)
{
    SEG(0xFF);
    COM(1 << dsp.com);

    if(dsp.com != dsp.dot){
        SEG(segCode[dsp.buf[dsp.com]]);
    }else{
        SEG(segCode[dsp.buf[dsp.com]] & 0x7F);
    }

    if(++dsp.com >= 8){
        dsp.com = 0;
    }
}

//
void InitDsp(void)
{
    dsp.buf[0] = 10;
    dsp.buf[1] = 10;
    dsp.buf[2] = 10;
    dsp.buf[3] = 10;
    dsp.buf[4] = 10;
    dsp.buf[5] = 10;
    dsp.buf[6] = 10;
    dsp.buf[7] = 10;
    dsp.dot = 255;
	dsp.SegDisplay = SegDisplay;
}